import { SDKBase, UserInfo } from "./SDKBase";


/**
 * 微信SDK
 */
export default class WeChatSDK implements SDKBase {
    wx: any = null
    /**
     * 初始化sdk配置
     */
    public init() {
        this.wx = window["wx"]
    }

    /**
     * 获取用户信息
     */
    public getUserInfo(): Promise<UserInfo> {
        return new Promise((resolve, reject) => {
            this.wx.getUserProfile({
                desc: '用于完善玩家资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
                success: (res) => {
                    console.log("[WeChatSDK] getUserProfile() res:", res)
                    let userInfo: UserInfo = {
                        avatarUrl: res.userInfo.avatarUrl,
                        nickName: res.userInfo.nickName
                    }
                    resolve(userInfo)
                },
                fail: () => {
                    console.warn('[WeChatSDK] wx.getUserProfile() failed')
                    reject(null)
                }
            })
        })
    }

    /**
     * 分享功能
     * @returns 
     */
    public share() {
        this.wx.shareAppMessage({
            title: "分享"
        })
    }
}